/**
 * @Author your name
 * @Date 2021-03-03 17:08:44
 * @LastEditTime 2021-03-04 10:19:11
 * @LastEditors Please set LastEditors
 * @Description In User Settings Edit
 * @FilePath \fed-e-task-04-06\code\angular-route\src\app\app-routing.module.ts
 */
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomeComponent } from './pages/home/home.component';
import { AboutComponent } from './pages/about/about.component';
import { RouterModule, Routes } from '@angular/router';
import { NotFoundComponent } from './pages/not-found/not-found.component';
import { NewsComponent } from './pages/news/news.component';
import { CompanyComponent } from './pages/company/company.component';
import { IndustryComponent } from './pages/industry/industry.component';
import { AuthGardGuard } from './guards/auth-gard.guard';
import { UnsaveGuard } from './guards/unsave.guard';
import { GetNameResolver } from './guards/get-name.resolver';

const routes: Routes = [
  {
    path: 'home',
    component: HomeComponent,
    canDeactivate: [UnsaveGuard],
    resolve: {
      name: GetNameResolver
    }
  },
  {
    path: 'about/:name',
    component: AboutComponent,
    canActivate: [ AuthGardGuard ]
  },
  {
    path: 'user',
    loadChildren: () => import('./user/user.module').then(m => {
      return m.UserModule
    })
  },
  {
    path: 'news',
    component: NewsComponent,
    children: [
      {
        path: 'company',
        component: CompanyComponent,
        outlet: 'left'
      },
      {
        path: 'industry',
        component: IndustryComponent,
        outlet: 'right'
      }
    ]
  },
  {
    path: '',
    // 重定向路由
    redirectTo: 'home',
    // 完全匹配
    pathMatch: 'full'
  },
  {
    path: '**',
    component: NotFoundComponent
  }
]

@NgModule({
  declarations: [],
  imports: [
    CommonModule,
    RouterModule.forRoot(routes, { useHash: true })
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }
